package com.ruoyi.Warehouse.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.Warehouse.domain.Pricehistory;
import com.ruoyi.Warehouse.service.IPricehistoryService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 价格历史表Controller
 * 
 * @author ruoyi
 * @date 2025-06-16
 */
@Controller
@RequestMapping("/pims/pricehistory")
public class PricehistoryController extends BaseController
{
    private String prefix = "pims/pricehistory";

    @Autowired
    private IPricehistoryService pricehistoryService;

    @RequiresPermissions("pims:pricehistory:view")
    @GetMapping()
    public String pricehistory()
    {
        return prefix + "/pricehistory";
    }

    /**
     * 查询价格历史表列表
     */
    @RequiresPermissions("pims:pricehistory:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(Pricehistory pricehistory)
    {
        startPage();
        List<Pricehistory> list = pricehistoryService.selectPricehistoryList(pricehistory);
        return getDataTable(list);
    }

    /**
     * 导出价格历史表列表
     */
    @RequiresPermissions("pims:pricehistory:export")
    @Log(title = "价格历史表", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(Pricehistory pricehistory)
    {
        List<Pricehistory> list = pricehistoryService.selectPricehistoryList(pricehistory);
        ExcelUtil<Pricehistory> util = new ExcelUtil<Pricehistory>(Pricehistory.class);
        return util.exportExcel(list, "价格历史表数据");
    }

    /**
     * 新增价格历史表
     */
    @RequiresPermissions("pims:pricehistory:add")
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存价格历史表
     */
    @RequiresPermissions("pims:pricehistory:add")
    @Log(title = "价格历史表", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(Pricehistory pricehistory)
    {
        return toAjax(pricehistoryService.insertPricehistory(pricehistory));
    }

    /**
     * 修改价格历史表
     */
    @RequiresPermissions("pims:pricehistory:edit")
    @GetMapping("/edit/{historyId}")
    public String edit(@PathVariable("historyId") Long historyId, ModelMap mmap)
    {
        Pricehistory pricehistory = pricehistoryService.selectPricehistoryByHistoryId(historyId);
        mmap.put("pricehistory", pricehistory);
        return prefix + "/edit";
    }

    /**
     * 修改保存价格历史表
     */
    @RequiresPermissions("pims:pricehistory:edit")
    @Log(title = "价格历史表", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(Pricehistory pricehistory)
    {
        return toAjax(pricehistoryService.updatePricehistory(pricehistory));
    }

    /**
     * 删除价格历史表
     */
    @RequiresPermissions("pims:pricehistory:remove")
    @Log(title = "价格历史表", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(pricehistoryService.deletePricehistoryByHistoryIds(ids));
    }
}
